package com.hmall.order.interceptor;

import com.hmall.common.basecontext.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class MyHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userId = request.getHeader("authorization");
        log.info("[订单微服务拦截器开启成功===>拦截参数为authorization：{}]",userId);
        BaseContext.setCurrentId(Long.parseLong(userId));
        log.info("[订单微服务拦截器开启成功===>将参数放于ThreadLocal中，设置完成。]");
        return true;
    }
}